/*
 * @Author: Dorange.Wang
 * @Date: 2021-06-30 16:05:36
 * @LastEditors: wangming
 * @LastEditTime: 2022-01-18 18:22:36
 * @Description: file content
 */
import { MOS_ENABLED } from '@/utils/const'
import stores from 'store2'
import { getMosConfig } from '@/apis/paas/MosEndpoint.js'
const state = {
  enabled: false,
  domain: ''
}
const mutations = {
  SET_ENABLED(state, payload) {
    state.enabled = payload
  },
  SET_DOMAIN(state, payload) {
    state.domain = payload
  }
}
const actions = {
  async GET_MOS_CONFIG({ commit }) {
    const config = await getMosConfig()
    const { mosEnable: enabled, mosUrl: domain } = config
    commit('SET_ENABLED', enabled)
    commit('SET_DOMAIN', domain)
    stores.set(MOS_ENABLED, enabled)
    return config
  }
}
const getters = {
  MOS_ENABLED(state) {
    return state.enabled
  },
  MOS_DOMAIN(state) {
    return state.domain
  }
}

export default {
  getters,
  state,
  mutations,
  actions
}
